﻿
    using Chain.BLL;
//    using ChainStock.Controls;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public partial class UserList : PageBase
    {


        protected void btnUserSearch_Click1(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.GetSysUserList(this.Condition());
        }

        protected string Condition()
        {
            string strShopID = this.sltShop.Value;
            string strGroupID = this.sltUserGroupID.Value;
            StringBuilder strSql = new StringBuilder();
            strSql.Append(" 1=1 ");
            if (strShopID != "")
            {
                strSql.AppendFormat(" and UserShopID={0}", strShopID);
            }
            if (strGroupID != "")
            {
                strSql.AppendFormat(" and UserGroupID ={0}", strGroupID);
            }
            return strSql.ToString();
        }

        protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.NetPagerParameter.PageSize = int.Parse(this.drpPageSize.SelectedValue);
            this.GetSysUserList(this.Condition());
        }

        private void GetSysUserList(string strSql)
        {
            new SysGroup();
            SysUser user = new SysUser();
            int Counts = this.NetPagerParameter.RecordCount;
            strSql = strSql + " and SysUser.UserShopID = SysShop.ShopID and SysUser.UserGroupID = SysGroup.GroupID ";
            switch (PubFunction.curParameter.istry)
            {
                case 0:
                    strSql = strSql + "and SysUser.UserID>1";
                    break;

                case 2:
                    strSql = strSql + "and SysUser.UserID>1";
                    break;
            }
            if (base._UserGroupID != 1)
            {
                object name3 = strSql;
                strSql = string.Concat(new object[] { name3, " and UserGroupID in (select GroupID from SysGroup where ParentIDStr like '%/", base._UserGroupID, "/%')" });
            }
            else
            {
                object name5 = strSql;
                strSql = string.Concat(new object[] { name5, " and UserGroupID in (select GroupID from SysGroup where ParentIDStr like '%/", base._UserGroupID, "/%' or GroupID=", base._UserGroupID, ")" });
            }
            DataTable db = user.GetListSP(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts, new string[] { PubFunction.GetShopAuthority(base._UserShopID, "UserShopID", strSql) }).Tables[0];
            this.NetPagerParameter.RecordCount = Counts;
            this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[] { this.NetPagerParameter.CurrentPageIndex, this.NetPagerParameter.PageCount, this.NetPagerParameter.RecordCount, this.NetPagerParameter.PageSize });
            this.gvSysUserList.DataSource = db;
            this.gvSysUserList.DataBind();
            PageBase.BindSerialRepeater(this.gvSysUserList, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
        }

        protected void gvSysUserList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item)
            {
                DataRowView dr = (DataRowView) e.Item.DataItem;
                if (dr["UserID"].ToString() == "1")
                {
                    HtmlAnchor hyUserDelete = (HtmlAnchor) e.Item.FindControl("hyUserDel");
                    hyUserDelete.Attributes.Add("style", "display:none");
                }
                if (PubFunction.curParameter.istry != 1)
                {
                    HtmlAnchor hyEditPwd = (HtmlAnchor) e.Item.FindControl("hyEditPwd");
                    hyEditPwd.Attributes.Add("style", "display:none");
                }
            }
        }

        protected void NetPagerParameter_PageChanging(object src, PageChangingEventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = e.NewPageIndex;
            this.GetSysUserList(this.Condition());
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                PubFunction.BindShopSelect(base._UserShopID, this.sltShop, true);
                PubFunction.BindAuthoritySelelct(base._UserShopID, base._UserGroupID, this.sltUserGroupID, true);
                PubFunction.BindShopSelect(base._UserShopID, this.sltShopInfo, false);
                this.GetSysUserList(this.Condition());
                this.txtShopId.Value = this._UserShopID.ToString();
                this.txtGroupID.Value = this._UserGroupID.ToString();
            }
        }
    }


